package main

import (
	"fmt"
	"log"
	"os"
	"runtime"
	"strconv"
	"time"
)

//文件是否存在??
func Exist(filename string) bool {
	_, err := os.Stat(filename)
	return err == nil || os.IsExist(err)
}

func main() {
	//file, err := os.Create("test.log")
	//打开文件,才有读写,创建模式
	file, err := os.OpenFile("test.log", os.O_RDWR|os.O_CREATE, 0666)
	defer file.Close()
	if err == nil {
		//defer file.Close()
	}

	if err != nil {
		log.Println(err)
		return
	}

	now := time.Now() //获取当前的时间

	b := "this is a test,now is :" + strconv.FormatInt(now.Unix(), 10) //转换成时间戳,在转换成字符串
	time := now.Format("2006/01/02 15:04:05")                          //设置时间格式的,必须使用这几个字符占位才可以的!!!
	b = b + "\r\n" + "time is : " + time
	log.Println(b)

	//或许系统的类型
	run_os := runtime.GOOS
	log.Println(run_os)

	fmt.EOL
	file.WriteString(b)

}
